package cn.codeforfun.controller;

import cn.codeforfun.handler.Handler;
import cn.codeforfun.service.TestService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @author Administrator
 * @date 2017/2/28
 */
@RestController
public class IndexController {
  @Resource
  private Handler handler;
  @Resource
  private TestService testService;

  @RequestMapping
  public void index() throws InterruptedException, ExecutionException {
    Future<String> stringFuture1 = handler.handler1();
    Future<String> stringFuture2 = handler.handler2();
    Future<String> stringFuture3 = handler.handler3();
    while (true) {
      if (stringFuture1.isDone() &&
              stringFuture2.isDone() &&
              stringFuture3.isDone()
              ) {
        System.out.println(stringFuture1.get());
        System.out.println(stringFuture2.get());
        System.out.println(stringFuture3.get());
        break;
      }
    }
  }
  @GetMapping("/test")
  public String test() throws InterruptedException {
    testService.async();
    return "ok";
  }
}
